package edu.gxmzu.task.controller;

import edu.gxmzu.task.entity.Work1;
import edu.gxmzu.task.entity.Works;
import edu.gxmzu.task.models.WorkModel;
import edu.gxmzu.task.params.AdminWorkParam;
import edu.gxmzu.task.service.WorksService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 莫松华
 */
@RestController
@Tag(name="管理员查询任务")
public class WorksController {

    @Autowired
    private WorksService worksService;
    @Operation(summary = "管理员查询全部任务")
    @GetMapping("/worksList")
    public Map<String, Object> getTaskList() {
        Map<String, Object> result = new HashMap<>();
        List<Work1> taskList = worksService.getTaskList();
        if (Objects.nonNull(taskList)){
            result.put("code", "200");
            result.put("data", taskList);
            result.put("state", "请求成功");
        }else{
            result.put("code", "401");
            result.put("data", null);
        }
        return result;
    }
    @Operation(summary = "管理员查询指派任务")
    @PostMapping("/AssignedList")
    public Map<String, Object> getAssignedList(@RequestBody AdminWorkParam param) {
        Map<String, Object> result = new HashMap<>();
        List<Works> taskList = worksService.getAssignedList(param);
        if (Objects.nonNull(taskList)){
            result.put("code", "200");
            result.put("data", taskList);
            result.put("state", "请求成功");
        }else{
            result.put("code", "401");
            result.put("data", null);
        }
        return result;
    }

}
